package cn.tedu.bonfire.front.payment.controller;

import cn.tedu.bonfire.common.pojo.authentication.CurrentPrincipal;
import cn.tedu.bonfire.common.web.JsonResult;
import cn.tedu.bonfire.front.payment.pojo.param.EditorPayParam;
import cn.tedu.bonfire.front.payment.pojo.param.RewardParam;
import cn.tedu.bonfire.front.payment.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

@Api(tags = "打赏支付页面")
@RestController
@RequestMapping("reward")
public class UserController {

    @Autowired
    private IUserService userService;

    @PostMapping("/")
    @ApiOperation("打赏")
    public JsonResult reward( RewardParam rewardParam,
                              @AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal) {
        userService.reward(rewardParam,currentPrincipal);
        return JsonResult.ok();
    }

    @PostMapping("/editorPay")
    @ApiOperation("付费解锁")
    public JsonResult editorPay(EditorPayParam editorPayParam,
                                @AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal) {
        userService.editorPay(editorPayParam,currentPrincipal);
        return JsonResult.ok();
    }

    @PostMapping("/checkExpiration")
    @ApiOperation("检查期限")
    public JsonResult checkExpiration(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal) {
        boolean check = userService.checkExpiration(currentPrincipal);
        return JsonResult.ok(check);
    }
    @PostMapping("/selectExpiration")
    @ApiOperation("检查剩余时间")
    public JsonResult selectExpiration(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal) {
        int expiration = userService.selectExpiration(currentPrincipal);
        return JsonResult.ok(expiration);
    }

    @GetMapping("/withdrawCash")
    @ApiOperation("提现")
    public JsonResult withdrawal(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal) {
//        System.out.println(currentPrincipal);
        userService.withdrawal(currentPrincipal);
        return JsonResult.ok();
    }


}
